<?php
if (!defined('MVC_ROOT_DIR'))  die('Hacking attempt');
/**
 * 无限极子菜单
 *
 */
class Menu
{
	public $rsOut;
	
	/**
	 * 
	 * 获取子菜单，$rs为数组array(0=>array(),1=>array()...)
	 * @param array $rs
	 * @param string $id
	 */
	public function getChildMenu($rs,$id='0')
	{		
		$res = array ();//初始化下级分类数组
		$j=0;
		for($i = 0; $i < count ( $rs ); $i ++) {  
        	if ($rs [$i] ['menu_parent_id'] == $id) {
            	$res [$j] = $rs [$i];
            	$j ++;
            }
    	}      	
    	for($i = 0; $i < count ( $res ); $i ++) {  
        	 
        	$this->rsOut = $this->rsOut. "<li> \n"; 
        	
        	$this->rsOut = $this->rsOut
        				. '<a href="#" url="'.MVC_WEB_DIR.$res[$i]['menu_action'].'" ';
        				if (self::haveChild($rs,$res[$i]['menu_id'])){
        					$this->rsOut=$this->rsOut.'class="parent"';
        				}
        				$this->rsOut=$this->rsOut.' id="menus"><span style="font-weight: normal;font-size: 13px;">'
        				.$res [$i] ['menu_zh_name']
        				.'</span></a>'; 
    		if (self::haveChild($rs,$res[$i]['menu_id'])){
        		$this->rsOut = $this->rsOut. "<div><ul>"; 
        	}    		
        	self::getChildMenu($rs,$res [$i] ['menu_id'] ); //继续找下一级，找到没有下级为止
        	
    		if (self::haveChild($rs,$res[$i]['menu_id'])){
        		$this->rsOut = $this->rsOut. "</ul></div>"; 
        	}
        	$this->rsOut = $this->rsOut. "</li>";        	
     	}    	
     	return $this->rsOut;		
	}
    
	static function haveChild($rs,$id){
		for ($i=0;$i<count($rs);$i++){
			if ($rs[$i]['menu_parent_id']==$id){
				return true;
			}
		}
		return false;
	}
		
}